package com.example.encryptedsharedpreferences

import javax.crypto.Cipher
import javax.crypto.spec.SecretKeySpec

class EncryptionImpl : IEncryption {

    val KEY: String = "12345678"

    override fun encrypt(input: ByteArray): ByteArray {

        val secretKeySpec = SecretKeySpec(KEY.toByteArray(), "DES")
        val cipher = Cipher.getInstance("DES")
        cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec)
        return cipher.doFinal(input)
    }

    override fun decrypt(input: ByteArray): ByteArray {
        val secretKeySpec = SecretKeySpec(KEY.toByteArray(), "DES")
        val cipher = Cipher.getInstance("DES")
        cipher.init(Cipher.DECRYPT_MODE, secretKeySpec)
        return cipher.doFinal(input)
    }
}